<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<style>
    #sourceType {
        display: block;
        width: 100%;
        padding-left: 10px;
        height: 38px;
        line-height: 1.3;
        line-height: 38px \9;
        border-width: 1px;
        border-style: solid;
        background-color: #fff;
        border-radius: 2px;
    }
</style>
<body>

<div class="demoTable">
    搜索ID：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
        {#        <div class="layui-input-inline">#}

        {#        </div>#}
    </div>
    <div class="layui-inline">
        <select name="sourceType" id="sourceType">
            <option value="XLWB" selected="">新浪微博</option>
            <option value="JRTT">今日头条</option>
            <option value="SGSS">搜狗</option>
        </select>
    </div>

    <button class="layui-btn" data-type="reload">搜索</button>
    <button class="layui-btn" data-type="loadData">爬取数据</button>
</div>

<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>


<script src="/static/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use('table', function () {
        var table = layui.table;
        var $ = layui.$;
        //方法级渲染
        table.render({
            elem: '#LAY_table_user'
            , url: '/sys/opinionData'
            , where: {
                content: $('#demoReload').val(),
                sourceType: $("#sourceType ").val()
            }
            , cols: [[
                {checkbox: true, fixed: true}
                , {field: 'id', title: 'ID', width: 80, sort: true, fixed: true}
                , {field: 'content', title: '内容', width: 180}
                , {field: 'url', title: '地址', width: 180, sort: true}
                , {
                    field: 'sourceType', title: '数据来源', width: 180, templet(val) {
                        val = val.sourceType;
                        return "XLWB" == val ? "新浪微博" : "JRTT" == val ? "今日头条" : "搜狗搜索"
                    }
                }
            ]]
            , id: 'testReload'
            , page: true
            , height: 310
        });

        var active = {
            reload: function () {
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        content: $("#demoReload").val(),
                        sourceType: $("#sourceType ").val()
                    }
                }, 'data');
            },
            loadData: function () {
                $.ajax({
                    url: "//getHotWords",
                    success: function (response) {
                        this.reload();
                    },
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

</body>
</html>